<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;

use think\Request;

use cmf\controller\AdminBaseController;
use app\admin\model\GPSCategory;
use app\admin\model\GPSCategoryItem;
use app\admin\model\GPSMigration;
use app\admin\model\GPSDetail;

class GPSDetailController extends AdminBaseController
{
    /**
     * 采集信息列表 
     * Author Raven
     * Date 2018-10-18
     * Params [params]
     * @param  integer $category_id [分类id]
     */
    public function index(Request $request, $category_id = 0)
    {
        if(empty($category_id)){
            $this->error("params_error");
        }


        $GPSDetail = new GPSDetail();

        $res = $GPSDetail->index($category_id);
        
        return $this->fetch('GPSDetail/index', $res);
    }

    /**
     * 采集信息详情 
     * Author Raven
     * Date 2018-10-18
     * Params [params]
     * @param  integer $category_id [分类id]
     * @param  integer $detail_id   [详情id]
     */
    public function detail(Request $request, $category_id = 0, $detail_id = 0)
    {
        if(empty($category_id) || empty($detail_id)){
            $this->error("params_error");
        }

        $GPSDetail = new GPSDetail();

        if($_POST){
            $res = $GPSDetail->updateDetail($category_id, $detail_id, $_POST);

            if($res == false){
                $this->error('保存添加失败');
            }

            $this->success('success');
        }

        $res = $GPSDetail->detail($category_id, $detail_id);
        
        return $this->fetch('GPSDetail/detail', $res);
    }
}
